/**
 * \* Created with IntelliJ IDEA.
 * \* User: 冯若航
 * \* Date: 2021/5/12
 * \* Time: 17:19
 * \* To change this template use File | Settings | File Templates.
 * \* Description:
 * \
 */
public class 数字序列中某一位的数字 {
    public int findNthDigit(int n) {
        //分别是位数字，起始数字，数位数量
        //1,2,3,4...
        //1,10,100,1000...
        //9,90,2700,36000...
        int digit = 1;
        long start = 1;
        long count = 9;
        while (n>count){
            n-=count;
            digit+=1;
            start*=10;
            count=digit*start*9;
        }
        long num=start+(n-1)/digit;
        return Long.toString(num).charAt((n - 1) % digit) - '0';
    }
}